﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;

namespace WPFExcelReport
{
    public partial class TAB50YD
    {
        TGBBS13 control;
        public TAB50YD()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            InitializeComponent();

        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            FTAUTOSUM = true;
            TCOUNT1 = "单数";
            TKEY1 = "计划";
            KEY1 = "ABPSOLLMENGE5";
            SKEY1 = "ABPAUFKRS";
            TKEY2 = "实际KG";
            KEY2 = "ABPEAKG";
            SKEY2 = "ABPAUFKRS";
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }
        public override void OnFAUFChg(string auf)
        {
            if (!IsAuto)
                return;
            TBMain.Clear();
            if (auf.Length < 12)
                return;
            dwData = TBMain.NewRow(); 
            dwData["ABPMANDANT"] = app.Mandant;
            dwData["ABPAUFKRS"] = auf.Substring(1, 2);
            dwData["ABPAUFLFD"] = auf.Substring(3, 6);
            dwData["ABPAUFPOS"] = auf.Substring(9,3);
           
            SResult = TMV.QABP36(dwData);
            MergeData(SResult, true);
            base.OnFAUFChg(auf);
        }
        public override void OnAutoChg(bool value)
        {
            OnFAUFChg(FAUF);
            OnEXAUFChg(PRART);
            base.OnAutoChg(value);
        }
        public override void OnEXAUFChg(string art)
        {
            if (!IsAuto)
                return;
            if (FAUF.Length > 0)
                return;
            TBMain.Clear();
            if (art.Length < 63)
                return;
            dwData = TBMain.NewRow();
            dwData["ABPMANDANT"] = app.Mandant;
            dwData["ABPAUFKRS"] = KRS;
            dwData["ABPWAKZ"] = "R";
            dwData["ABPVAR"] = art.Substring(21, 2).PadRight(3);
            if (JW=="J")
            {
                dwData["ABPWAKZ"] = "K";
                dwData["ABPVAR"] = "1  ";
            }           
            dwData["ABPART"] = art.Substring(1, 20);          
            dwData["ABPFARBE"] = art.Substring(23, 10);
            dwData["ABPBESCHICH"] = "".PadRight(10);
            dwData["ABPDESS"] = "".PadRight(10);
            dwData["ABPCOLORIT"] = "".PadRight(10);
            SResult = TMV.QABP37(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(art);
        }
        private void ShowDetail_Click(object sender, RoutedEventArgs e)
        {
            if (!IsShowOutPut)
            {
                IsShowOutPut = true;
                return;
            }
            IsShowOutPut = false;
        }
    }
}
